/*
 * @Author: szx
 * @Date: 2022-01-12 12:41:53
 * @LastEditTime: 2022-01-12 13:14:51
 * @Description:
 * @FilePath: \leetcode\300-399\334\334.js
 */
/**
 * @param {number[]} nums
 * @return {boolean}
 */
// var increasingTriplet = function (nums) {
//     const length = nums.length;
//     if (length < 3) return false;
//     const left = new Array(length - 1).fill(0);
//     left[0] = nums[0];
//     const right = new Array(length - 1).fill(0);
//     right[length - 2] = nums[length - 1];
//     for (let i = 1; i < length - 1; i++) {
//         left[i] = Math.min(nums[i], left[i - 1]);
//         right[length - 1 - i] = Math.max(nums[length - i - 1], left[i + 1]);
//     }
//     for (let i = 1; i < length - 1; i++) {
//         if (nums[i] > left[i - 1] && nums[i] < right[i + 1]) return true;
//     }
//     return false;
// };

var increasingTriplet = function (nums) {
    const length = nums.length;
    if (length < 3) return false;
    let first = nums[0];
    let second = Number.MAX_VALUE;
    for (let i = 1; i < length; i++) {
        if (nums[i] > second) return true;
        else if (nums[i] > first) second = nums[i];
        else first = nums[i];
    }
    return false;
};
